package com.maixin.code.interceptor;

import java.io.IOException;
import java.sql.SQLException;

import org.hibernate.hql.ast.QuerySyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class ExceptionInterceptor extends AbstractInterceptor {
	private static final Logger logger = LoggerFactory.getLogger("business");
	private static final long serialVersionUID = 1L;

	public String intercept(ActionInvocation invocation) throws Exception {
		String result = "";
		String actionName = invocation.getInvocationContext().getName();

		try {
			result = invocation.invoke();
		} catch (QuerySyntaxException ex) {
			logger.error("异常拦截器拦截到异常：HQL语句出错！" + "<br>" + "action的为:"
					+ actionName + "<br>" + "异常 的 详 细信息：" + "<br>"
					+ ex.toString());
		} catch (SQLException ex) {
			logger.error("异常拦截器拦截到异常：SQL语句出错！" + "<br>" + "action的名称为:"
					+ actionName + "<br>" + "异常的详细信息：" + "<br>" + ex.toString());
		} catch (NullPointerException ex) {
			logger.error("异常拦截器拦截到异常：调用了未经初始化的对象或者是不存在的对象！" + "<br>"
					+ "action的名称为:" + actionName + "<br>" + "异常的详细信息：" + "<br>"
					+ ex.toString());
		} catch (IOException ex) {
			logger.error("异常拦截器拦截到异常：IO异常！" + "<br>" + "action的名称为:"
					+ actionName + "<br>"+ ex.toString());
			
		}catch(Exception ex){
			logger.error("异常拦截器拦截到异常：Exception！" + "<br>" + "action的名称为:"
					+ actionName + "<br>"+ ex.toString());
		}
		return result;
	}
}
